package cn.concurrence.cas;

import java.util.concurrent.atomic.AtomicReference;

import cn.concurrence.dto.UserDTO;

/**
 * @author summit
 * @since 2022/4/21 10:47
 */
public class AtomicReferenceTest {

	public static void main(String[] args) {
		UserDTO user1 = new UserDTO();
		UserDTO user2 = new UserDTO();
		AtomicReference<UserDTO> ar = new AtomicReference<>();
		ar.set(user1);

		System.out.println("第一次设值" + ar.compareAndSet(user1, user2) + "  " + ar.get());

		System.out.println("第二次设值" + ar.compareAndSet(user1, user2) + "  " + ar.get());

		/**
		 * 第一次设值true  UserDTO(id=null, name=null)
		 * 第二次设值false  UserDTO(id=null, name=null)
		 */
	}
}
